package ldkxingzhe.ldkxingzhedemo.menu;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.PopupMenu;

import ldkxingzhe.ldkxingzhedemo.R;


/**
 * Created by ke on 15-8-22.
 */
public class PopupMenuActivity extends Activity implements PopupMenu.OnMenuItemClickListener{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_popup_menu);
    }

    public void showPopMenu(View view){
        PopupMenu popupMenu = new PopupMenu(this,view);
        MenuInflater menuInflater = popupMenu.getMenuInflater();
        menuInflater.inflate(R.menu.option_menu,popupMenu.getMenu());
        popupMenu.setOnMenuItemClickListener(this);
        popupMenu.show();
    }

    @Override
    public boolean onMenuItemClick(MenuItem item) {
        Log.d("TAG","item.getItemId = " + item.getItemId());
        switch (item.getItemId()){
            case R.id.item1:
                Log.d("TAG","item1 was clicked");
                break;
            case R.id.item2:
                Log.d("TAG","item2 was clicked");
                break;
        }
        return true;
    }
}
